
/**
 * @param {string[]} strs
 * @return {string[][]}
 */
var groupAnagrams = function (strs) {
  let map=new Map()
    for(let i=0;i<strs.length;i++){
        //1.字符串内部排序
        let indexKey=strs[i].split("").sort().join('')

        //2.键存在，添加这个字符串
        if(map.has(indexKey)){
            map.get(indexKey).push(strs[i])
        }
        else{
            //3.键不存在，创建这个键并添加
            let item=[strs[i]]
            map.set(indexKey,item)
        }
    }

    //4.遍历map,变为string[][]
    return  Array.from(map.values())
};
let strs = ["eat", "tea", "tan", "ate", "nat", "bat"]
console.log(groupAnagrams(strs));//[["bat"],["nat","tan"],["ate","eat","tea"]]


